package com.haotian.xml;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class _SoapXmlUtil {
	public static String xml2soap(String xml) {
		StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?> ");
		sb.append("<soap:Envelope ").append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ")
				.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ")
				.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ").append("<soap:Body>").append(xml)
				.append("</soap:Body>").append("</soap:Envelope>");
		return sb.toString();
	}

	public static String soap2XML(String soapXml) throws DocumentException, IOException {

		ByteArrayInputStream bais = new ByteArrayInputStream(soapXml.getBytes("UTF-8"));

		Document doc = new SAXReader().read(bais);

		bais.close();

		Element body = doc.getRootElement().element("Body");
		
		Element e = (Element) body.elementIterator().next();
		
		return e.asXML();
		
	}

}
